*Note: Android SDK and Java JDK (when developing for Android) - have to be ticked in the installation modules when installing Unity.*
2022.3.3f1
https://unity.com/releases/editor/whats-new/2022.3.3
Note: Do not click the blue download link. If you download directly from this website it is cubersome to install the dependencies. Unity is version-sensitive, and it needs to be exactly this version
Be sure to select the appropriate dependencies below.
Note: this installs roughly 20gb of data, make sure you have enough free space on your computer.
Run Unity Hub. Create a new Unity Project. Be sure to select the correct Unity Version as basis for the project 2022.3.3f1
Install Unity Packages for XR (Mixed Reality)
Access the Package Manager
Switch to the Unity Registry
Search & Install AR Foundation
, repeat for ARCore XR plugin
Select No
on whether to use the new input system package.
Add ARCore Unity Extensions. Select Add package from git URL
, https://github.com/google-ar/arcore-unity-extensions.git
Verify AR Foundation
, ARCore XR plugin
, ARCore Extensions
are installed
A Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. Scene view is your interactive view into the world you are creating. You can use the Scene view to select and position scenery, characters, Cameras , lights, and all other types of Objects. Selecting, manipulating, and modifying GameObjects in the Scene view are some of the first skills you must learn to begin working in Unity.
The Gizmo allows you to quickly modify the viewing angle and the projection mode.
You can use the Arrow Keys to move around the Scene as though walking through it. The up and down arrows move the Camera forward and backward in the direction it is facing. The left and right arrows pan the view sideways.
You can use the following Buttons to select, move, rotate, scale. This toolbar is located on the top left corner.
The Game view is rendered from the Camera(s) in your application. It represents your final, published application. You need to use one or more Cameras to control what the player sees when they are using your application. In AR, we will see a mixed environment between real and digital objects, as the camera orientation is constantly changing by our movement in space.
Play mode
Use the buttons in the Toolbar to control the Editor Play mode and see how your published application plays. An important fact is that, in Play mode, any changes you make are temporary, and are reset when you exit Play mode.
The Hierarchy window displays every GameObject in a Scene, such as models, Cameras, or Prefabs. You can use the Hierarchy window to sort and group the GameObjects you use in a Scene.
The default Hierarchy window view when you open a new Unity project
The Inspector Window is being used to view and edit properties and settings for almost everything in the Unity Editor. In the Inspector Window, one can add or remove Components , which enable different features.. We will see what these are soon. → More Info
The Project window displays all of the files related to your Project and is the main way you can navigate and find Assets and other Project files in your application. When you start a new Project by default this window is open. However, if you cannot find it, or it is closed, you can open it via Window > General > Project or use the keyboard command Ctrl + 9 (Command + 9 on macOS).
GameObjects are the fundamental objects in Unity that represent 3d objects, props and scenery. They do not accomplish much in themselves but they act as containers for Components, which implement the real functionality.
A GameObject always has a Transform component attached (to represent position and orientation) and it is not possible to remove this. The other components that give the object its functionality can be added from the editor’s Component menu or from a script. There are also many useful pre-constructed objects (primitive shapes, Cameras, etc) available on the GameObject > 3D Object menu (more info: Primitive Objects )
Components implement functionalities on the GameObjects. For example, a light object is created by attaching a light component to a GameObject. Components are contained by GameObjects. Unity has many built-in components, and you can create your own by writing scripts that inherit from the MonoBehaviour class. C# is the programming language which we use to write code.
→ More Info about Scripting in Unity
A simple Cube GameObject with several Components
Prefabs allow you to create, configure, and store a GameObject complete with all its components, property values, and child GameObjects .The Prefab Asset acts as a template from which you can create new prefab instances in the scene.
Unity uses the concept of parent-child hierarchies, or parenting, to group GameObjects. An object can contain other GameObjects that inherit its properties. You can link GameObjects together to help move, scale, or transform a collection of GameObjects. When you move the top-level object, or parent GameObject, you also move all child GameObjects. You can also create nested parent-child GameObjects. All nested objects are still descendants of the original parent GameObject, or root GameObject.Child GameObjects inherit the movement and rotation of the parent GameObject. To learn more about this, see documentation on the Transform component!
Child 1 and Child 2 are the child GameObjects of Parent. Child 3 is a child GameObject of Child 2, and a descendant GameObject of Parent.
To create a new GameObject in the Hierarchy window:
→ You can also press Ctrl+Shift+N (Windows) or Command+Shift+N (macOS) to create a new empty GameObject.
To create a child GameObject:
Drag Object 4 (selected) onto the parent GameObject, Object 1(highlighted in a blue) to create a child GameObject.
You can add a new GameObject into the Hierarchy view as the parent of existing GameObjects.
To create a parent GameObject:
You can also press Ctrl+Shift+G (Windows) or Command+Shift+G (macOS) to create a parent GameObject.
→ You can also click and drag GameObjects inside, or outside parent GameObjects.
To duplicate GameObjects, right-click the target GameObject and select Duplicate.
→ You can also press Ctrl+D (Windows) or Command+D (macOS) to duplicate the selected GameObject.
Try inserting multiple GameObjects like cubes, spheres and Planes in the Scene. Use the basic tools to Move, Rotate and Scale the Objects and go to the Inspector Window. Try to transform them Manually by Inserting Values on Position, Rotation and Scale.
Note: To quickly reset all the transform values, you can right click on the transform title, and click Reset
In the Project Window, go to Assets, right click on the empty space and make a new folder by going to Create> Folder. Name it Materials.
Double click on the folder, right click on the empty space and make a new material by going to Create>Material. A new Material is created.
Click on the color palette on the Inspector and select a color of your choice.
Drag and drop the material from the Assets Folder on the desired objects
Note: You can explore different Material Properties, such as Transparency (in Rendering Mode), Emission (“glowy” effect, especially when combined with Bloom Rendering effects in Gaming), or add a Texture as a Map, similarly to other softwares.
Move the camera to look at the cube.
You see a small icon appearing at the bottom, showing how the Game Mode will look like through this camera.
Tip: If you don’t see the camera and light icons, try to click on the Gizmos button on top.
An event is a message sent to an object to signal that an event happened such as the pressing of a button has occurred. An event sender pushes notifications that an event happened and a receiver receives that notification and defines to respond to it. The object that raises the event is called the event sender. The event sender doesn’t know which object will receive the events it raises.
A script in Unity is not like the traditional idea of a program where the code runs continuously in a loop until it completes its task. Instead, Unity passes control to a script intermittently by calling certain functions that are declared within it. Once a function has finished executing, control is passed back to Unity. These functions are known as event functions since they are activated by Unity in response to events that occur during gameplay. Unity uses a naming scheme to identify which function to call for a particular event. For example, you will already have seen the Update function (called before a frame update occurs) and the Start function (called just before the object’s first frame update).
Note: Many more event functions are available in Unity; the full list can be found in the script reference page for the MonoBehaviour class along with details of their usage. The following are some of the most common and important events.
Let’s create our first C# script to interact with the Cube we made previously.
Click on the cube GameObject you created, go to the Inspector and click Add Component. Go to New Script , name it Zoom and click on Create and Add.
Set Visual Studio Code to the default interface in Unity settings. Go to File>Preferences>External Tools>External Script Editor and select Visual Studio Code
Double click on the Script name, or right click>Edit Script
Open the file with Visual Studio Code. Login with your Microsoft account, or create a new one.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Zoom : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Unity’s base class that all scripts should derive from if they are used as components.
MonoBehaviour is a part of the UnityEngine namespace and implements a big list of event functions.
Unity adds the Start and Update methods by default to all new scripts.
Start: Runs once, at the first time the component is initialized.
Update: Runs on every frame (e.g. if it is 60fps, it runs 60 times per second!)
→ We will write a script in Update, but will create an Event that triggers the command only when we press a button.
Note: Remember to always put a semicolon (;) at the end of every line_
public class Zoom: MonoBehaviour {
public GameObject cube;
// Start is called before the first frame update
void Start() {
}
// Update is called once per frame
void Update() {
}
}
We put the statement in the update, so that the script is checking constantly for our input.
void Update()
{
if(Input.GetKey(KeyCode.Space))
{
//do something here
}
}
void Update()
{
if(Input.GetKey(KeyCode.Space))
{
cube.transform.localScale += (Vector3.one*1.00001f)/100;
}
}
Note: We used a small value, since it will move fast.
Link the Public GameObject cube;
variable that you just created in code to the actual cube instance in Unity. Click the buttom under Zoom, and select the cube.
Save the script, go back to Unity and Play the Scene.
Long Press the SpaceBar of your keyboard and watch the cube zoom exponentially.
Note: Any changes to code or scene must be made after Existing Play Mode or they will be temporary.
transform.localScale += (Vector3.one*1.00001f)/100;
Save it and run the code again. It still works because the script is self-referencing the object that the component is added to.Note: The Unity Asset Store is home to a growing library of free and commercial assets created both by Unity Technologies and also members of the community. A wide variety of assets are available, covering everything from textures, models and animations, to whole project examples, tutorials and Extension Assets.
Find and download the free asset 5 animated Voxel animals.
https://assetstore.unity.com/packages/3d/characters/animals/5-animated-voxel-animals-145754
After clicking the Open in Unity button, you will be redirected to the Unity software, on the package manager. Make sure you are in Packages: My Assets. Click Import
A window pops up. When importing a package, you can select the parts you want to import. For now, we will import everything. Click Import.
→ Make sure the Transform position values are set to 0,0,0
Go to Assets>VoxelAnimals>Assets>Prefabs and drag and drop a character on the Scene or the Hierarchy. Make sure it is correctly placed on the plane.
Tip: To zoom in on an object fast, you can first select it from the Hierarchy or the scene and then click on the “F” button on your keyboard.
You can move the camera to a position where you see everything nicely.
By clicking on the Keyboard arrows your character will move, by clicking on the Space Button the character will jump! If the cube gets bigger, the dog collides with it and might fall. The character is a Rigid Body with Collision properties.
A game is rather like an animation where the animation frames are generated on the fly. A key concept in games programming is that of making changes to position, state and behavior of objects in the game just before each frame is rendered. The Update function is the main place for this kind of code in Unity. Update is called before the frame is rendered and also before animations are calculated.
Below is an example of the code that would make the animated figure move:
void Update()
{
float distance = speed * Time.deltaTime * Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * distance);
}
→ More Information on execution order of events in unity
ARCore is Google’s platform for building augmented reality experiences. Using different APIs. ARCore enables your phone to sense its environment, understand the world and interact with information. Some of the APIs are available across Android and iOS to enable shared AR experiences.
ARCore uses three key capabilities to integrate virtual content with the real world as seen through your phone’s camera:
ARCore is designed to work on a wide variety of qualified Android phones running Android 7.0 (Nougat) and later. A full list of all supported devices is available here.
Fundamentally, ARCore is doing two things:
ARCore’s motion tracking technology uses the phone’s camera to identify interesting points, called features, and tracks how those points move over time. With a combination of the movement of these points and readings from the phone’s inertial sensors, ARCore determines both the position and orientation of the phone as it moves through space.
In addition to identifying key points, ARCore can detect flat surfaces, like a table or the floor, and can also estimate the average lighting in the area around it.
→ For a more detailed breakdown of how ARCore works, check out __fundamental concepts_._
Android // Android NDK // Unity (AR Foundation) // iOS // Unreal
Note: In our class/tutorial, we will focus on Unity’s AR Foundation Framework, and build the application for Android devices.
AR Foundation is a cross-platform framework that allows you to build augmented reality experiences once, then build for either Android or iOS devices. ARCore Extensions for AR
AR Foundation allows you to work with augmented reality platforms in a multi-platform way within Unity. This package presents an interface for Unity developers to use, but doesn’t implement any AR features itself. To use AR Foundation on a target device, you also need separate packages for the target platforms officially supported by Unity:
Windows XR Plug-in on HoloLens
AR Foundation is a set of MonoBehaviours and APIs for dealing with devices that support the following concepts. A few of them are: